import {
    SET_SELFCOURSE
} from '../mutation-types';
import api from '../../api';

const state = {
    result: [],
    message: null,
}
const mutations = {
        [SET_SELFCOURSE](state, data) {
            state.result = data;
            // state.result.time = (data.time > 60 ? parseInt(data.time / 60) : 1);
            // state.result.kcal = data.kcal.toFixed(0);
            state.message = data.message;
        }
    }
    // ACTION
const actions = {
    GET_SELFCOURSE: ({ commit, dispatch }, date) => {
        //让loading界面显示
        // dispatch('CHANGE_LOADING_SHOW').then(
        api.getCourseInfo(date).then(response => {
                if (response.data.code == 100) {
                    console.log(response.data.result);
                    commit(SET_SELFCOURSE, response.data.result, response.data.message ? response.data.message : null);
                } else {
                    commit(SET_SELFCOURSE, response.data.message);
                }
                // 关闭loading界面
                // dispatch('HIDDEN_LOADING_SHOW')
            })
            // )
    }
}
export default {
    state,
    actions,
    mutations
}